﻿@{
    ViewBag.Title = "来料输入";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    $(function () {
        initControl();
        gridList();
        textChange();
    });
    function initControl() {
        //发生方式
        $("#txtFDocuTypeNO").bindSelect({
            url: "/VBaseData/V_BUS_SJ_Dictionary/GetWayNodesForNotice",
            id: "FTypeNO",
            text: "FTypeName"
        });
        $("#txtFDocuTypeNO").val("CR").trigger("change");
        //制造厂家
        $("#txtFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName"
        });
        //容器编号
        $("#txtFContainerNO").bindSelect({
            url: "/BaseData/ZSJ_21_RQ_DatContainer/GetGridJson",
            id: "FContainerNO",
            text: "FContainerNO"
        });
        //托盘编号
        $("#txtFPalletNO").bindSelect({
            url: "/BaseData/ZSJ_22_TP_Pallet/GetGridJson",
            id: "PalletNO",
            text: "PalletNO"
        });
        //绑定是否空箱入库的事件
        $("#txtIsEmptyBox").change(function () {
            valueChange();
        })
        //初始化入库日期
        SetSomeData();
    }
    function SetSomeData()
    {
        var currentDate = new Date();
        $("#txtFCurDate").val(currentDate.format("yyyy-MM-dd"));
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/VBaseData/V_ZSJ_12_GH_SuProduction_DatStor/GetGridJson?docuTypeNO=" + $("#txtFDocuTypeNO").val(),
            height: $(window).height() - 270,
            colModel: [
            { label: '选择', name: 'XZ', width: 40, align: 'center' },
            { label: "id", name: "FRegisterID", width: 120, align: 'center', hidden: true },
            { label: '入库日期', name: 'FCurDate', width: 100, align: 'center' },
            { label: "来料单位", name: "FHappenCompanyNO", width: 120, align: 'left' },
            { label: "来料单位名称", name: "FHappenCompanyName", width: 120, align: 'left' },
            { label: '发生方式', name: 'FDocTypeName', width: 80, align: 'left' },
            { label: '零部件号', name: 'FProductionNO', width: 140, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 160, align: 'left' },
            { label: '批次号', name: 'FBatchNo', width: 80, align: 'center' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'right' },
            { label: '实际装箱', name: 'FFactContent', width: 80, align: 'right' },
            { label: '标准装箱', name: 'FContent', width: 80, align: 'right' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'center' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'right' },
            { label: '实际托盘容量', name: 'FPalletFactContent', width: 80, align: 'right' },
            { label: '标准托盘容量', name: 'FPalletContent', width: 80, align: 'right' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '备注', name: 'FDescription', width: 80, align: 'left' },
            { label: '制造厂家', name: 'FProCompanyNO', width: 80, align: 'left' },
            { label: '制造厂家名称', name: 'FProCompanyName', width: 80, align: 'left' },
            { label: '零件状态代码', name: 'FProductionTypeNO', width: 80, align: 'left', hidden: true },
            { label: '零件状态', name: 'FProductionTypeName', width: 80, align: 'left' },
            { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left' },
            { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
            { label: '输入时间', name: 'FCreateTime', width: 80, align: 'center' },
            ],
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                $("#form1").formSerialize(rowData, "txt");
                $("#hideFProCompanyNO").val(rowData.FProCompanyNO);
                SetSomeData();
            }
        });
      
        $("#btn_search").click(function () {
            Query();
        });

    }

    function Query(){
        var $FProCompanyNO = $("#txtFProCompanyNO").val();
        if($FProCompanyNO=="==请选择=="){
            $FProCompanyNO="";
        }
        $("#gridList").jqGrid('setGridParam', {
            postData: { productionNO: $("#txtFProductionNO1").val(), productionName: $("#txtFProductionName1").val(), companyNameOrNo: $FProCompanyNO, docuTypeNO: $("#txtFDocuTypeNO").val(), currentDate: $("#txtFCurDate").val() },
        }).trigger('reloadGrid');
    }

    function selectFDocuTypeNOChange() {
        $("#FHappenCompanyNO").clearSelect();
        $("#FHappenCompanyNO").bindSelect({
            url: "/VBaseData/V_ZSJ_B1_GH_SupplierForRegister/GetList?typeFlag=" + $("#txtFDocuTypeNO").val(),
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
    }

    function selectChange() {
        var $FProCompanyNO = $("#txtFProCompanyNO").val();
        var $hideFProCompanyNO = $("#hideFProCompanyNO").val();
        if ($FProCompanyNO != $hideFProCompanyNO) {
            Query();
        }
    }
    function textChange()
    {
        $("#form1").find(".decimal").keyup(function () {
            valueChange();
        });
    }
    function valueChange() {
        var $FactContent = 1;
        var $FQuantity_KP = $("#txtFQuantity_KP").val();
        var $FFactContent = $("#txtFFactContent").val();
        var $FPalletFactContent = $("#txtFPalletFactContent").val();
        if ($FFactContent != "") {
            if (!$("#txtIsEmptyBox").prop('checked')) {
                $FactContent = Math.floor($FQuantity_KP / $FFactContent);
            }
            else {
                $FactContent = Math.ceil($FQuantity_KP / $FFactContent);
            }

            $("#txtFContainerQuantity").val($FactContent);
        }
        if ($FPalletFactContent != "") {
            var $FPalletQuantity = 0;
            //if (!$("#txtIsEmptyBox").prop('checked')) {
            //    $FPalletQuantity = Math.floor($FactContent / $FPalletFactContent);
            //}
            //else {
            //    $FPalletQuantity = Math.ceil($FactContent / $FPalletFactContent);
            //}
            $FPalletQuantity = Math.ceil($FactContent / $FPalletFactContent);
            $("#txtFPalletQuantity").val($FPalletQuantity);
        }
    }

    function btn_Return() {
        parent.$.reload();
        parent.$.detailClose();
    }
    function btn_Ok() {
        if (!$('#form1').formValid()) {
            return false;
        }
        var postData = $("#form1").formSerialize();
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/SaveDJ_StoRegister",
            param: postData,
            success: function () {
                Query();
            }
        });
    }
   
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
        <form id="form1">
            <div><input id="txtFRegisterID" name="FRegisterID" type="hidden" /><input id="txtFProductionTypeNO" name="FProductionTypeNO" type="hidden" />
                <input id="hideFProCompanyNO" type="hidden" /></div>
            <div style="padding-top: 1px;margin-left:10px;">

                <table  class="form" style="width:97%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px; border-bottom:1px solid #ccc;">
                        <tr>
                            <th class="formTitle" style="width:60px;">发生方式</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFDocuTypeNO" name="FDocuTypeNO" onchange="selectFDocuTypeNOChange();" class="form-control">
                                    <option >==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:60px;">零部件号</th>
                            <td class="formValue" style="width:120px;">
                                <input id="txtFProductionNO1" type="text" class="form-control "  />
                            </td>
                            <th class="formTitle" style="width:100px;">零件名称</th>
                            <td class="formValue" style="width:120px;">
                                <input id="txtFProductionName1" type="text" class="form-control "  />
                            </td>
                            <th class="formTitle" style="width:155px;">制造厂家</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFProCompanyNO" name="FProCompanyNO" onchange="selectChange();" class="form-control">
                                    <option >==请选择==</option>
                                </select>
                            </td>
                            <td style="padding: 5px 10px;">
                                <div class="btn-group" style="margin-left:70px;margin-bottom:-2px;">
                                    <a id="btn_search" class="btn btn-primary center-block  " onclick="btn_search();"><span class="glyphicon glyphicon-search"></span> 查询</a>
                                </div>
                            </td>
                            <td style="padding: 5px 10px;">
                                <div class="btn-group" >
                                    <a id="" class="btn btn-primary center-block " onclick="btn_Ok()"><span class="glyphicon glyphicon-ok"></span> 输入</a>
                                    <a id="" class="btn btn-primary center-block  " onclick="btn_Return()"><span class="glyphicon glyphicon-remove"></span> 返回</a>
                                </div>
                            </td>

                        </tr>
                    </table>
                
                <div style="margin-top:5px;margin-bottom:6px;">
                    <span style="font-size: 16px;text-align: right;margin-left: 24px;font-weight: bold;">请输入:</span>
                    <table class="form" style="width:97%;text-align:left;display:inline;">
                        <tr>
                            <th class="formTitle" style="width:60px;">入库日期</th>
                            <td class="formValue" style="width:160px;height:20px;">
                                <input id="txtFCurDate" name="FCurDate" type="text" class="form-control required" onfocus="WdatePicker()" />
                            </td>

                            <th class="formTitle" style="width:100px;">凭证编号</th>
                            <td class="formValue" style="width:120px;height:20px;">
                                <input name="FVoucherNo" type="text" class="form-control " />
                            </td>

                            <th class="formTitle" style="width:100px;">容器编号</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFContainerNO" name="FContainerNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>

                            <th class="formTitle">托盘编号</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFPalletNO" name="FPalletNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle" style="width:60px;">来料单位</th>
                            <td class="formValue" style="width:180px;">
                                <select id="FHappenCompanyNO" name="FHappenCompanyNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>

                            <th class="formTitle" style="width:100px;">批次号</th>
                            <td class="formValue" style="width:120px;">
                                <input name="FBatchNo" type="text" class="form-control" />
                            </td>

                            <th class="formTitle" style="width:100px;">标准装箱</th>
                            <td class="formValue">
                                <input id="txtFContent" name="FContent" type="text" readonly="readonly" class="form-control text-right required " style="width:80px;margin-left:0px;" /><label class="suffix">件/箱</label>
                            </td>

                            <th class="formTitle" style="width:100px;">标准托盘容量</th>
                            <td class="formValue">
                                <input id="txtFPalletContent" name="FPalletContent" type="text" readonly="readonly" class="form-control text-right required" style="width:80px;margin-left:0px;" /><label class="suffix">箱/托</label>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle" style="width:60px;">零部件号</th>
                            <td class="formValue" style="width:120px;">
                                <input id="txtFProductionNO" name="FProductionNO" type="text" readonly="readonly" class="form-control required" />
                            </td>
                            <th class="formTitle" style="width:100px;">开票数量</th>
                            <td class="formValue">
                                <input id="txtFQuantity_KP" name="FQuantity_KP" type="text" class="form-control text-right required  decimal" min="1" style="width:80px;margin-left:0px;" /><label class="suffix">件</label>
                            </td>
                            <th class="formTitle" style="width:100px;">实际装箱</th>
                            <td class="formValue">
                                <input id="txtFFactContent" name="FFactContent" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label class="suffix ">件/箱</label>
                            </td>

                            <th class="formTitle" style="width:100px;">实际托盘容量</th>
                            <td class="formValue">
                                <input id="txtFPalletFactContent" name="FPalletFactContent" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label class="suffix">箱/托</label>
                            </td>


                        </tr>
                        <tr>
                            <th class="formTitle" style="width:60px;">备注</th>
                            <td class="formValue" colspan="2">
                                <input id="txtFDescription" name="FDescription" type="text" class="form-control " />
                            </td>
                            <td class="formValue">
                                <input id="txtIsEmptyBox" type="checkbox" checked="checked" /><span>是否空箱入库</span>
                            </td>
                            <th class="formTitle" style="width:100px;">容器数量</th>
                            <td class="formValue">
                                <input id="txtFContainerQuantity" name="FContainerQuantity" type="text" readonly="readonly" class="form-control text-right required" style="width:60px;margin-left:0px;" /><label class="suffix">箱</label>
                            </td>
                            <th class="formTitle" style="width:100px;">托盘数量</th>
                            <td class="formValue" >
                                <input id="txtFPalletQuantity" name="FPalletQuantity" type="text"  readonly="readonly" class="form-control text-right required" style="width:60px;margin-left:0px;" /><label class="suffix">托</label>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </form>
        <div style="">
            <table id="gridList"></table>
        </div>
    </div>
</div>


